package com.jiyun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.jumin.ChengYuanClient;
import com.jiyun.mapper.PendingSigningMapper;
import com.jiyun.mapper.ResidentsMapper;
import com.jiyun.model.sign.PendingSigning;
import com.jiyun.model.sign.Residents;
import com.jiyun.model.sign.dto.ResidentsQuery;
import com.jiyun.service.IResidentsService;
import com.jiyun.vo.chengyuan.ChengyuanVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 针对表【-Residents】的业务操作的Service实现类
 *
 * @author ???
 * @since 2024-09-27
 */
@Service
public class ResidentsServiceImpl extends ServiceImpl<ResidentsMapper, Residents> implements IResidentsService {

    @Override
    public IPage<Residents> getPageList(ResidentsQuery query){
        //1.创建查询条件
        QueryWrapper<Residents> qw = new QueryWrapper<>();
        //ToDo 查询条件

        //2.组件分页数据
        IPage<Residents> page = new Page<>(query.getCurrentPage(), query.getPageSize());
        //3.查询
        baseMapper.selectPage(page,qw);
        //4.返回
        return page;
    }
    @Autowired
    private ChengYuanClient chengYuanClient;
    @Resource
    private PendingSigningMapper pendingSigningMapper;

    @Override
    public Residents findByPendIdResidents(Integer pendingSigningId) {
        LambdaQueryWrapper<Residents> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Residents::getPendingSigningId, pendingSigningId);
        Residents residents = baseMapper.selectOne(wrapper);
        PendingSigning pendingSigning = pendingSigningMapper.selectById(residents.getPendingSigningId());
        Integer id = pendingSigning.getJuminId();
        List<ChengyuanVO> chengyuanVOS = chengYuanClient.fandGuanxi(id);
        residents.setChengyuanList(chengyuanVOS);
        return residents;
    }
}
